<template>
  <div class="app-container org">
    <el-card style="width: 100%">
      <p class="pinformation">搜索条件</p>
      <el-form :model="queryForm" ref="queryRef" label-width="80" :inline="true">
        <el-form-item label="方案编号：" prop="projectCode">
          <el-input clearable v-model.trim="queryForm.projectCode" @keyup.enter="handleQuery"></el-input>
        </el-form-item>
        <el-form-item label="受检单位：" prop="sjCustomName">
          <el-input clearable v-model="queryForm.sjCustomName" @keyup.enter="handleQuery"></el-input>
        </el-form-item>
        <el-form-item label="委托单位：" prop="wtCustomName">
          <el-input clearable v-model="queryForm.wtCustomName" @keyup.enter="handleQuery"></el-input>
        </el-form-item>
        <el-form-item label="要求完成时间：" label-width="110">
          <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
            start-placeholder="开始日期" end-placeholder="结束日期" style="width: 260px"></el-date-picker>
        </el-form-item>
        <el-form-item label="紧急程度：" prop="degree">
          <el-select v-model="queryForm.degree" style="width: 100px" placeholder="紧急程度" clearable filterable>
            <el-option v-for="dict in sys_degree" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否分包：" prop="packageStatus">
          <el-select clearable v-model="queryForm.packageStatus" style="width: 90px">
            <el-option v-for="dict in isPackageList" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="handleQuery">搜索</el-button>
          <el-button class="business resetBtn" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row>
        <p class="pinformation" style="margin-top: 8px">实时任务汇总</p>
        <p class="totalStyle" style="margin-top: 6px">共 {{ total }} 条数据</p>
        <el-form-item label="方案评审中：" label-width="100">
          {{ statisticsForm.projectReviewCount }}</el-form-item>
        <el-form-item label="采样中：" label-width="80">
          {{ statisticsForm.cyCount }}</el-form-item>
        <el-form-item label="实验分析中：" label-width="100">
          {{ statisticsForm.syCount }}</el-form-item>
        <el-form-item label="报告评审中：" label-width="130">
          {{ statisticsForm.reportReviewCount }}</el-form-item>
        <el-form-item label="待发放报告：" label-width="100">
          {{ statisticsForm.reportOutCount }}</el-form-item>
      </el-row>
      <div class="main_body" id="container" :style="'height:' + height + 'px'">
        <!-- <el-scrollbar :height="height + 'px'" v-loading="loading"> -->
        <div class="scroll-box">
          <div style="padding: 5px; border-bottom: 1px solid #ddd" v-for="item in scheduleList">
            <el-row>
              <el-col :span="5">
                <el-row>
                  <el-col :span="11">
                    <el-form-item label="方案编号：" style="margin-bottom: 0px !important">{{ item.projectCode
                    }}</el-form-item>
                  </el-col>
                  <el-col :span="13">
                    <el-form-item label="项目负责人：" style="margin-bottom: 0px !important">{{ item.projectUserName
                    }}</el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="方案名称：" style="margin-bottom: 0px !important">{{ item.projectName }}</el-form-item>
                <el-form-item label="起止时间：" style="margin-bottom: 0px !important">{{ item.planDate }}至{{ item.endTime
                }}</el-form-item>
              </el-col>
              <el-col :span="19">
                <el-row>
                  <div v-for="(row, index) in item.progressList"
                    style="padding-right: 2px; padding-left: 2px;cursor: pointer;"
                    @click="handleDetail(item.projectId, row.progressType)">
                    <el-progress :percentage="percentage(row)" :stroke-width="24" :show-text="false"
                      style="margin-top: 1vh; font-size: 14px; width: 100px">
                    </el-progress>
                    <span style="position: relative; top: -21px; left: 2.1vw; font-size: 13px">{{
                      row.progressRate && row.progressRate != "0%"
                      ? row.progressRate
                      : "　"
                    }}</span>
                    <div style="margin-top: -1vh; font-size: 14px; text-align: center">
                      {{ row.progressName }}
                    </div>
                  </div>
                </el-row>
              </el-col>
            </el-row>
          </div>
          <!-- </el-scrollbar> -->
        </div>
      </div>
      <pagination v-show="total > 0" :total="total" v-model:page="queryForm.pageNum" v-model:limit="queryForm.pageSize"
        @pagination="handleProgressList" />
    </el-card>
  </div>
</template>

<script setup name="Ssrw">
const router = useRouter();
const queryForm = ref({ pageNum: 1, pageSize: 10, packageStatus: -1 });
const statisticsForm = ref({});
const height = ref(100);
const loading = ref(false);
import {
  queryProgressListOfProject,
  queryProgressStatisticsOfProject,
} from "@/api/taskProgressDetails/index";
const dateRange = ref([]);
const scheduleList = ref([]);
const total = ref(0);
const { proxy } = getCurrentInstance();
const { sys_degree } = proxy.useDict("sys_degree");
const isPackageList = ref([
  { value: -1, label: "不限" },
  { value: 0, label: "否" },
  { value: 3, label: "是" },
]);
function handleQuery() {
  queryForm.value.pageNum = 1;
  handleProgressList();
  handleProgressStatistics();
}

function handleProgressList() {
  loading.value = true;
  queryProgressListOfProject(proxy.addDateRange(queryForm.value, dateRange.value))
    .then((res) => {
      scheduleList.value = res.rows;
      total.value = res.total;
      loading.value = false;
    })
    .catch((err) => {
      loading.value = false;
    });
}

function handleProgressStatistics() {
  queryProgressStatisticsOfProject(
    proxy.addDateRange(queryForm.value, dateRange.value)
  ).then((res) => {
    statisticsForm.value = res.data;
  });
}
handleQuery();
function percentage(val) {
  if(val.projectId == '1792788732094660610'){
    debugger;
  }
  if (!val.progressRate || val.progressRate == "") {
    return 0;
  }
  const progressRates = val.progressRate.split("/");
  if (progressRates.length > 1) {
    try {
      if(parseInt(progressRates[1]) == 0){
        return 0;
      }
      return (parseInt(progressRates[0]) / parseInt(progressRates[1])) * 100;
    } catch (e) {
      return 0;
    }
  }
  return parseInt(val.progressRate.replace("%", ""));
}
function handleDetail(projectId, progressType) {
  if (!projectId) {
    return;
  }
  router.push({
    path: "/projectProgress/detail",
    query: {
      projectId: projectId,
      progressType: progressType
    },
  });
}

function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

function getHeight() {
  var box = document.getElementById("container");
  var boxDistanceFromTop = box.getBoundingClientRect().top;
  height.value = window.innerHeight - boxDistanceFromTop - 71;
}
onMounted(() => {
  nextTick(function () {
    getHeight();
    window.addEventListener("resize", getHeight);
  });
});
onUpdated(() => {
  nextTick(() => {
    getHeight();
  });
});

onBeforeUnmount(() => {
  window.removeEventListener("resize", getHeight);
});
</script>

<style scoped lang="scss">
.main_body {
  border: solid 2px #b6c2e2;
  border-radius: 10px;

  .scroll-box {
    // background-color: aqua;
    // scroll-y
    overflow-y: auto;
    height: 100%;
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }

    // &::-webkit-scrollbar { /* WebKit浏览器的滚动条样式 */
    //     width: 10px;
    // }

    // &::-webkit-scrollbar-track { /* 滚动条轨道的样式 */
    //     background-color: #f1f1f1;
    // }

    // &::-webkit-scrollbar-thumb { /* 滚动条滑块的样式 */
    //     background-color: #888;
    // }

    // &::-webkit-scrollbar-thumb:hover { /* 滚动条滑块的悬停样式 */
    //     background-color: #555;
    // }
  }
}

.el-form-item {
  margin-bottom: 3px !important;
  overflow-wrap: anywhere !important;
}
</style>
